package com.example.bjsfpost.domain;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;

import static com.example.bjsfpost.controllers.BjsfApiPostController.ERROR;

/**
 * Description Excel错误消息的父类
 * Create by WangMing
 * Date 2021/8/16
 */
@Data
public class ErrorExcelData implements Serializable {
    @ExcelProperty(value = "错误提示" , order = 0)
    private String errorMessage;
    @ExcelProperty(value = "ITEM_ID" , order = 1)
    private String itemId;
    @ExcelProperty(value = "VERSION" , order = 2)
    private String version;
    @ExcelProperty(value = "MATL_TYPE" , order = 3)
    private String matlType;
    @ExcelProperty(value = "JSON" , order = 4)
    private String json;
    @ExcelProperty(value = "是否成功" , order = 5)
    //success / error
    private String successFlag;

    public static ErrorExcelData successButRepeat(ParamPostRequestDO requestDO){
        ErrorExcelData errorExcelData = new ErrorExcelData();
        BeanUtils.copyProperties(requestDO,errorExcelData);
        errorExcelData.setJson(JSONObject.toJSONString(requestDO));
        errorExcelData.setSuccessFlag(ERROR);
        errorExcelData.setErrorMessage("successButRepeat");
        return errorExcelData;
    }
    public static ErrorExcelData noSuccessButRepeat(ParamPostRequestDO requestDO){
        ErrorExcelData errorExcelData = new ErrorExcelData();
        BeanUtils.copyProperties(requestDO,errorExcelData);
        errorExcelData.setJson(JSONObject.toJSONString(requestDO));
        errorExcelData.setSuccessFlag(ERROR);
        errorExcelData.setErrorMessage("noSuccessButRepeat");
        return errorExcelData;
    }
}
